package com.kd.captcha.config;

import com.kd.captcha.CaptchaGenerator;
import com.kd.captcha.CaptchaManager;
import com.kd.captcha.ICaptchaManager;
import com.kd.captcha.storage.RedisCaptchaStorage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
@EnableConfigurationProperties(CaptchaProperties.class)
public class AutoConfiguration {

    @Bean
    public ICaptchaManager captchaManager(@Autowired StringRedisTemplate stringRedisTemplate, @Autowired CaptchaProperties captchaProperties) {
        return new CaptchaManager(new RedisCaptchaStorage(stringRedisTemplate, captchaProperties), new CaptchaGenerator());
    }
}
